<template>
	<view class="number">
		<view class="sub" @tap.stop="sub">
			<view class="icon iconfont">&#xe768;</view>
		</view>
		<view class="input">
			<input type="number" v-model="goodsInfo.number" />
		</view>
		<view class="add"  @tap.stop="add">
			<view class="icon iconfont">&#xe767;</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			goodsInfo: Object
		},
		methods: {
			// 减少数量
			sub() {
				if (this.goodsInfo.number <= 1) {
					return
				}
				this.goodsInfo.number--
				
				// 注册change事件
				this.$emit('change')
			},
			// 增加数量
			add() {
				this.goodsInfo.number++
				
				// 注册change事件
				this.$emit('change')
			}
		}
	}
</script>

<style lang="scss">
.number{
	display: flex;
	justify-content: center;
	align-items: center;
	
	.input{
		width: 80rpx;
		height: 60rpx;
		margin: 0 10rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		text-align: center;
		background-color: #f3f3f3;
		
		input{
			width: 80rpx;
			height: 60rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			text-align: center;
			font-size: 26rpx;
		}
	}
	
	.sub ,.add{
		width: 60rpx;
		height: 60rpx;
		background-color: #f3f3f3;
		border-radius: 5rpx;
		
		.icon{
			width: 60rpx;
			height: 60rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 30rpx;
		}
	}
}	
</style>
